<template>
  <div>
    <div>
      <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
        <el-breadcrumb-item :to="{ path: '/' }"><i class="el-icon-house" style="font-weight: bold">&nbsp;&nbsp;后台管理</i>
        </el-breadcrumb-item>
        <el-breadcrumb-item><i class="el-icon-s-claim">&nbsp;&nbsp;采购管理</i></el-breadcrumb-item>
        <el-breadcrumb-item><i class="el-icon-circle-plus">&nbsp;&nbsp;订单发票添加</i></el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div>
      <div class="data-canRead" style="width: 100%;background-color: white;height: auto">
        <el-steps :active="3" finish-status="success" simple style="background-color: white">
          <el-step title="商品编码"></el-step>
          <el-step title="商品信息"></el-step>
          <el-step title="上传图片"></el-step>
          <el-step title="等待上步"></el-step>
        </el-steps>
        <el-divider></el-divider>
<!--        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">-->
<!--          <el-form-item label="发票图片:" prop="invoice">-->
<!--            <el-upload-->
<!--                class="upload-demo"-->
<!--                drag-->
<!--                action=""-->
<!--                multiple>-->
<!--              <i class="el-icon-upload"></i>-->
<!--              <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>-->
<!--              <div class="el-upload__tip" slot="tip">只能上传jpg/png文件，且不超过500kb</div>-->
<!--            </el-upload>-->
<!--          </el-form-item>-->
          <el-upload
              action="/upload"
              name="picFile"
              limit="9"
              list-type="picture-card"
              :on-success="handleSuccess"
              :on-preview="handlePictureCardPreview"
              :on-remove="handleRemove">
            <i class="el-icon-plus"></i>
          </el-upload>

          <el-dialog :visible.sync="dialogVisible">
            <img width="100%" :src="dialogImageUrl" alt="">
          </el-dialog>
          <el-form>
            <el-button type="warning" @click="backToPreStep()" style="color: white">上一步</el-button>
            <el-button type="primary" @click="submitForm('ruleForm')" style="color: white">下一步</el-button>
            <el-button @click="resetForm('ruleForm')" style="color: white">重置</el-button>
          </el-form>

      </div>
    </div>
  </div>
</template>

<script>
export default {
  data(){
    return{
      dialogImageUrl: '',
      dialogVisible: false,
      fileList:[],
      ruleForm:{
        invoice:'',
      },
      rules:{
        invoice:[
          {required: true, message: '请选择图片', trigger: 'change'},
        ],
      },
    }
  },
  methods: {
    loadLocalRuleForm() {
      let localRuleFormString = localStorage.getItem('localRuleForm');
      let localRuleForm = JSON.parse(localRuleFormString);
      //如果local没有商品编就回到第一步
      if (!localRuleForm || !localRuleForm.commodityCode) {
        this.$router.push('oderAndInvoiceAdd1');
        return;
      }
      this.ruleForm = localRuleForm;
      // if (localRuleForm.invoice) {//如果包含图片信息，就将第四部的信息存到第三部
      //   this.ruleForm = localRuleForm;
      // } else {//如果没有就是从第二步来的，，就把第二步的信息给予
      //   this.ruleForm = localRuleForm;
      // }

    },

    backToPreStep() {
      this.$router.push('oderAndInvoiceAdd2');
    },

    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log("invoice:::"+ruleForm.invoice);
          this.$router.push('oderAndInvoiceAdd4');
        }
      });
    },

    resetForm(formName) {
      this.$refs[formName].resetFields();
    },

    handleSuccess(response,file,fileList){
      this.fileList = fileList;
    },
    handleRemove(file, fileList) {
      this.fileList = fileList;
      console.log(file, fileList);
      //删除请求
      axios.get("/remove?fileName="+file.response).then(function () {
        console.log("删除完成!");
      })
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    }

  },

  mounted() {
    this.loadLocalRuleForm();
  }
}
</script>

<style scoped>
* {
  color: black;
}

.data-canRead {
  width: 380px;
  height: 380px;
  margin-top: 15px;
  box-shadow: 0px 5px 5px #8d858a;
  float: left;
  margin-right: 16px;
}

</style>